﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataAccessLayer;
using Chefbook.HelperMethods;
using System.Globalization;

namespace Chefbook.UserActions
{
    public class CreateCategoryAction : UserActionBase
    {
        private Category createdCategory, parentCategory;
        private string createdCategoryName;

        public CreateCategoryAction(Category parent, string name)
        {
            parentCategory = parent;
            createdCategoryName = name;
        }

        public override void DoAction()
        {
            base.DoAction();
            createdCategory = Category.CreateCategory(1);
            createdCategory.Name = createdCategoryName;
            createdCategory.Id = DatabaseConnector.NextCategoryId;
            DatabaseConnector.AddToCategories(createdCategory);
            DatabaseConnector.SaveChanges();
        }

        public override void UndoAction()
        {
            base.UndoAction();
        }

        public override string ToString()
        {
            if (parentCategory != null)
            {
                return string.Format(CultureInfo.InvariantCulture, "Create Subcategory in Category '{0}'", parentCategory);
            }
            else
            {
                return "Create new Category";
            }
        }
    }
}
